package com.study.controller;

import com.study.entity.User;
import com.study.service.UserService;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/10/18.
 */
@Controller
public class UserController {
    private Logger logger= LoggerFactory.getLogger(User.class);
    @Autowired
    private UserService service;
    @PostMapping("doLogin")
    public String doLogin(User user ,HttpSession session){
        User u=service.findUser(user);
        logger.debug("当前登陆用户={}",u);
        if(u == null){
            return "redirect:login.jsp?error=账号或者密码错误";//重定向
        }else{
            session.setAttribute("user",u);
            return "main";
        }
    }
}
